<?php
require "/var/www/html/Sign/connect.php";
$id=$_POST['id'];
$psword=$_POST['psword'];
$class=170801;
$userName=$_POST['userName'];
$sql1="select id from userId where id='{$id}'";
$num=$conn->query($sql1);
if($row = mysqli_fetch_assoc($num))
{
    echo "<script>alert('学号已被注册.点击确定后自动跳转重新注册')</script>";
    echo '<script>location="../register.php"</script>';
}
//加密
$arr=str_split($psword);
$number=count($arr);
for ($j=0;$j<$number;$j++){
    $temp=ord($arr[$j])+3;
    $arr[$j]=chr($temp);

}
$arr=implode("",$arr);


$sign_time=0;
$sql1="insert into userId (id,userClass,userName,psword) values ('$id','$class','$userName','$arr')";
$num=$conn->query($sql1);
$sql2="insert into classmate (id,userClass,userName,sign_time) values ('$id','$class','$userName','$sign_time')";
$num1=$conn->query($sql2);
if($num&&$num1)
{
    echo "<script type='text/javascript'>alert('注册成功，点击确定后挑转')</script>";
    echo "<script>location='../login.php'</script>";

}
else{
    echo "<script type='text/javascript'>alert('注册失败，点击确定后重新注册')</script>";
    echo '<script>location="../register.php"</script>';
}

?>